<?php

namespace app\common\model\settings;

use app\common\model\BaseModel;


/**
 * 营业时间模型
 */
class Shoptime extends BaseModel
{
	protected $name = 'shop_time';
	protected $pk = 'shoptime_id';

	/**
     * 关联用户表
     */
    public function supplier()
    {
        return $this->BelongsTo('app\common\model\supplier\Supplier', 'shop_supplier_id', 'shop_supplier_id')->visible(['shop_supplier_id','name']);
    }

	/**
	 * 详情
	 */
	public static function detail($shoptime_id)
	{
		return (new static())->find($shoptime_id);
	}

	public static function createData($where)
	{
		$model = new static();
		$where['app_id'] = self::$app_id;
		$data = $model->save($where);
		return $data;
	}

	public static function one($where)
	{
		$where = self::disposeWhere($where);
		$model = new static();
		return $model->findOrFail($where);
	}

	public static function deleteData($where)
	{
		$model = new static();
		return $model->where(['shoptime_id'=>$where['id']])
		->where('shoptime_id','>',1)
		->delete();
	}

	public static function checkDuplicate($where){
		$model = new static();
		$duprs = $model->where($where)->find();
		if($duprs){
			return true;
		}
		return false;
	}
}